<%@ page language="java" import="java.util.*" contentType="text/html;charset=utf-8" %>
<%@ taglib uri="/struts-tags" prefix="s"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="<%=basePath %>js/jquery.js"></script>
<title>考试系统</title>
<style type="text/css">
<!--
body {
	margin-left: 3px;
	margin-top: 0px;
	margin-right: 3px;
	margin-bottom: 0px;
}
.STYLE1 {
	color: #e1e2e3;
	font-size: 12px;
}
.STYLE6 {color: #000000; font-size: 12; }
.STYLE10 {color: #000000; font-size: 12px; }
.STYLE19 {
	color: #344b50;
	font-size: 12px;
}
.STYLE21 {
	font-size: 12px;
	color: #3b6375;
}
.STYLE22 {
	font-size: 12px;
	color: #295568;
}
-->
</style>
		<script type="text/javascript">
		
		$(window).load(function() {
            
        });
		
		<s:if test = "add==1">
		var flag ;
		function add(o){
			flag = o;
			var id = o;
			// var par = ${paperid};
			$.get("../Teacher/TeacherAction!paperProAdd.action?programId="+id+"&paperId="+${paperid} , null,callback);
		}
		
		function callback(data){
			if(data != null){
				alert(data);
				$("#info"+flag).text("已添加");
				$("#add"+flag).hide();
				$("#delete"+flag).show();
			}
			else
				alert("添加失败！");
		}
		
		function del(o){
			flag = o;
			var id = o ;
			 //var par = ${paperid};
			$.get("../Teacher/TeacherAction!paperProDel.action?programId="+id+"&paperId="+${paperid} , null,delcallback);
		}
		function delcallback(data){
			if(data != null){
				alert(data);
				$("#info"+flag).text("");
				$("#add"+flag).show();
				$("#delete"+flag).hide();
			}
			else
				alert("删除失败！");
		}
		
		</s:if>
		
		var flag; 
		
		function ProgramDel(id,status){
			var id = id;
			var status = status;
			if(confirm("是否确定删除")){
				toProgramDel(id,status);
			}
		}
		
		function toProgramDel(id,status){
			flag = status
			$.get("<%=request.getContextPath()%>/Teacher/TeacherAction!ProgramDel.action?add=0&id="+id, null, ProgramDelBack);
		}
		
		function ProgramDelBack(data){
			if(data != null){
				alert(data);
				$("#"+flag).hide();
			}
			else
				alert("删除失败！");
		}
		
		
		function info(i){
			window.location.href="<%=basePath %>Teacher/TeacherAction!programInfo.action?id="+i;
			//window.open("../Teacher/TeacherAction!programInfo.action?id="+i,"","") 
		}
		</script>
</head>
<body>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td height="30"><table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td height="24" bgcolor="#353c44"><table width="100%" border="0" cellspacing="0" cellpadding="0">
          <tr>
            <td><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="6%" height="19" valign="bottom"><div align="center"><img src="images/tb.gif" width="14" height="14" /></div></td>
                <td width="94%" valign="bottom"><span class="STYLE1"> 编程题基本信息列表</span></td>
              </tr>
            </table></td>
            <td><div align="right"></div></td>
          </tr>
        </table></td>
      </tr>
    </table></td>
  </tr>
  <tr>
    <td><table width="100%" border="0" cellpadding="0" cellspacing="1" bgcolor="#a8c7ce">
    
    <tr>
		<div id='search_bar'>
    	<form action="<%=request.getContextPath()%>/Teacher/TeacherAction!ProgramList.action?" method='get'>

            <label>题目名称 </label>
            <input type='text' name='programming.title' class='input_text' style='margin-left:12px;' />
               
           <label>创建者</label>           
                  <input type='text' name='papername' class='input_text' style='margin-left:12px;' />
           <label>分数</label>    
           	<select name="programming.score">
				    <option value=""></option>
				    <option value="5">5</option>
				    <option value="6">6</option>
				    <option value="8">8</option>
				    <option value="10">10</option>
				    <option value="12">12</option>
				    <option value="15">15</option>
				    <option value="18">18</option>
				    <option value="20">20</option>
				    <option value="25">25</option>
				    <option value="30">30</option>
				    <option value="35">35</option>
				    <option value="40">40</option>
				</select>
            <input type='submit' value='查询' class='mysubmit' />         
        </form>
		</div>
   </tr>
    
      <tr>
        <td width="8%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">题目编号</span></div></td>
        <td width="25%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">题目标题</span></div></td>
        <td width="8%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">创建者</span></div></td>
        <td width="8%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">分数</span></div></td>
        <td width="8%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">公有or私有</span></div></td>
        <td width="14%" height="20" bgcolor="d3eaef" class="STYLE6"><div align="center"><span class="STYLE10">
        
        <s:if test="user.role==2">基本操作</s:if>
        <s:if test="add==1">	增加 </s:if>
      		&nbsp; &nbsp; 查看
        	</span></div></td>
      </tr>
      
      <s:iterator value="paperPage.list" id="program" status="status">
	  <tr id =<s:property value="#status.index"/> >
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"> <s:property value="#program.id" /> </div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#program.title" /></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#program.user.username" /></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center"><s:property value="#program.score" /></div></td>
        <td height="20" bgcolor="#FFFFFF" class="STYLE19"><div align="center">
        <s:if test="#program.visible == 0">公开</s:if>
        <s:else>私有</s:else>
        </div></td>
		<td height="20" bgcolor="#FFFFFF" ><div align="center"><span class="STYLE21">	
			
			<s:if test="add==1">
				<span id="info<s:property value="#program.id" />"></span>
				<s:set  value="programsId" name="list" ></s:set>
				
					<s:if test="#program.id in #list">
						<input type="button" style="display: none;" id ="add<s:property value="#program.id" />" value="添加"  onclick="add(<s:property value="#program.id" />)"/>
						<input type="button" id ="delete<s:property value="#program.id" />" value = "删除"  onclick="del(<s:property value="#program.id" />)"/>
					</s:if>
					<s:else>
						<input type="button" id ="add<s:property value="#program.id" />" value="添加"  onclick="add(<s:property value="#program.id" />)"/>
						<input type="button" id ="delete<s:property value="#program.id" />" value = "删除" style="display:none" onclick="del(<s:property value="#program.id" />)"/>
					</s:else>
				
			</s:if>
				
			<s:else>
				<a href="#" onclick="info(<s:property value="#program.id" />)">详细</a>
				<s:if test="#program.user.id == #session.loginUser.id ">
					<a href="#" onclick="ProgramDel(<s:property value='#program.id' />, <s:property value='#status.index'/> )">删除</a>
				</s:if>
			</s:else>
			
			 </span></div></td>
	  </tr>
	  </s:iterator>
    </table></td>
  </tr>
  <tr>
  </tr>
</table>


<div id='page'>
		
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=1&pagesize=10&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">First Page</a>
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=${paperPage.currentpage-1}&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">Prev Page</a>
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=${paperPage.currentpage}&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">[${paperPage.currentpage}]</a>
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=${paperPage.currentpage+1}&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">[${paperPage.currentpage+1}]</a>
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=${paperPage.currentpage+2}&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">[${paperPage.currentpage+2}]</a>
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=${paperPage.currentpage+3}&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">[${paperPage.currentpage+3}]</a>
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=${paperPage.currentpage+1}&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">Next Page</a>
    <a href="<%=request.getContextPath()%>//Teacher/TeacherAction!ProgramList.action?&currentpage=${paperPage.totalpagecount}&programming.title=${programming.title}&programming.score=${programming.score}&papername=${papername}">Last Page</a>
    <span>当前第${paperPage.currentpage}/${paperPage.totalpagecount}页</span>
</div>


<s:if test="add==1">
   		<span><a href="<%=path %>/Teacher/TeacherAction!paperInfo.action?paperId=${paper.id}"/>点此预览</a></span>
</s:if>


</body>
</html>
